<template>
    <el-dialog :title="form.id ? '编辑' : '新增'" v-model="visible"
      :close-on-click-modal="false" draggable>
      <el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="90px" v-loading="loading">
       <el-row :gutter="24">
    <el-col :span="12" class="mb20">
      <el-form-item label="title" prop="title">
        <el-input v-model="form.title" placeholder="请输入title"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="file_type" prop="fileType">
        <el-input v-model="form.fileType" placeholder="请输入file_type"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="工作路径" prop="workdir">
        <el-input v-model="form.workdir" placeholder="请输入工作路径"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="exec_ppk" prop="execPpk">
        <el-input v-model="form.execPpk" placeholder="请输入exec_ppk"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="来源客户端" prop="sourceClient">
        <el-input v-model="form.sourceClient" placeholder="请输入来源客户端"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="process_status" prop="processStatus">
        <el-input v-model="form.processStatus" placeholder="请输入process_status"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="coordinate_system" prop="coordinateSystem">
        <el-input v-model="form.coordinateSystem" placeholder="请输入coordinate_system"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="gga开始时间" prop="ggaStartTime">
        <el-input v-model="form.ggaStartTime" placeholder="请输入gga开始时间"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="gga结束时间" prop="ggaEndTime">
        <el-input v-model="form.ggaEndTime" placeholder="请输入gga结束时间"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="sp3_files" prop="sp3Files">
        <el-input v-model="form.sp3Files" placeholder="请输入sp3_files"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="diff_files" prop="diffFiles">
        <el-input v-model="form.diffFiles" placeholder="请输入diff_files"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="rnx_files" prop="rnxFiles">
        <el-input v-model="form.rnxFiles" placeholder="请输入rnx_files"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="计算成果文件" prop="resultFile">
        <el-input v-model="form.resultFile" placeholder="请输入计算成果文件"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="提示信息" prop="message">
        <el-input v-model="form.message" placeholder="请输入提示信息"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="cmcc_diff_flag" prop="cmccDiffFlag">
        <el-input v-model="form.cmccDiffFlag" placeholder="请输入cmcc_diff_flag"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="中移差分解算任务id" prop="cmccId">
        <el-input v-model="form.cmccId" placeholder="请输入中移差分解算任务id"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="原始GGA里程数" prop="originMileage">
        <el-input v-model="form.originMileage" placeholder="请输入原始GGA里程数"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="中移解算里程数" prop="cmccMileage">
        <el-input v-model="form.cmccMileage" placeholder="请输入中移解算里程数"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="cmcc日志" prop="cmccLog">
        <el-input v-model="form.cmccLog" placeholder="请输入cmcc日志"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="差分解算任务提交时间" prop="cmccStartTime">
        <el-input v-model="form.cmccStartTime" placeholder="请输入差分解算任务提交时间"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="差分解算任务完成时间" prop="cmccEndTime">
        <el-input v-model="form.cmccEndTime" placeholder="请输入差分解算任务完成时间"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="deduction_status" prop="deductionStatus">
        <el-input v-model="form.deductionStatus" placeholder="请输入deduction_status"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="deduction_relate_ids" prop="deductionRelateIds">
        <el-input v-model="form.deductionRelateIds" placeholder="请输入deduction_relate_ids"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="download_sp3_flag" prop="downloadSp3Flag">
        <el-input v-model="form.downloadSp3Flag" placeholder="请输入download_sp3_flag"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="sp3文件下载地址" prop="downloadSp3Log">
        <el-input v-model="form.downloadSp3Log" placeholder="请输入sp3文件下载地址"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="sth2rnx_flag" prop="sth2rnxFlag">
        <el-input v-model="form.sth2rnxFlag" placeholder="请输入sth2rnx_flag"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="sth转rnx日志" prop="sth2rnxLog">
        <el-input v-model="form.sth2rnxLog" placeholder="请输入sth转rnx日志"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="重试标识" prop="restartFlag">
        <el-input v-model="form.restartFlag" placeholder="请输入重试标识"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="PPK开始计算时间" prop="ppkStartTime">
        <el-input v-model="form.ppkStartTime" placeholder="请输入PPK开始计算时间"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="PPK解算任务命令" prop="ppkCommand">
        <el-input v-model="form.ppkCommand" placeholder="请输入PPK解算任务命令"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="开始处理时间" prop="startTime">
        <el-input v-model="form.startTime" placeholder="请输入开始处理时间"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="结束处理时间" prop="endTime">
        <el-input v-model="form.endTime" placeholder="请输入结束处理时间"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="创建人" prop="createUser">
        <el-input v-model="form.createUser" placeholder="请输入创建人"/>
      </el-form-item>
      </el-col>

    <el-col :span="12" class="mb20">
      <el-form-item label="更新人" prop="updateUser">
        <el-input v-model="form.updateUser" placeholder="请输入更新人"/>
      </el-form-item>
      </el-col>

			</el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="visible = false">取 消</el-button>
          <el-button type="primary" @click="onSubmit" :disabled="loading">确 认</el-button>
        </span>
      </template>
    </el-dialog>
</template>

<script setup lang="ts" name="SthcloudPpkSloveTaskDialog">
import { useDict } from '/@/hooks/dict';
import { useMessage } from "/@/hooks/message";
import { getObj, addObj, putObj, validateExist } from '/@/api/sthcloud/sthcloudPpkSloveTask'
import { rule } from '/@/utils/validate';
const emit = defineEmits(['refresh']);

// 定义变量内容
const dataFormRef = ref();
const visible = ref(false)
const loading = ref(false)
// 定义字典

// 提交表单数据
const form = reactive({
		id:'',
	  title: '',
	  fileType: '',
	  workdir: '',
	  execPpk: '',
	  sourceClient: '',
	  processStatus: '',
	  coordinateSystem: '',
	  ggaStartTime: '',
	  ggaEndTime: '',
	  sp3Files: '',
	  diffFiles: '',
	  rnxFiles: '',
	  resultFile: '',
	  message: '',
	  cmccDiffFlag: '',
	  cmccId: '',
	  originMileage: '',
	  cmccMileage: '',
	  cmccLog: '',
	  cmccStartTime: '',
	  cmccEndTime: '',
	  deductionStatus: '',
	  deductionRelateIds: '',
	  downloadSp3Flag: '',
	  downloadSp3Log: '',
	  sth2rnxFlag: '',
	  sth2rnxLog: '',
	  restartFlag: '',
	  ppkStartTime: '',
	  ppkCommand: '',
	  startTime: '',
	  endTime: '',
	  createUser: '',
	  updateUser: '',
});

// 定义校验规则
const dataRules = ref({
})

// 打开弹窗
const openDialog = (id: string) => {
  visible.value = true
  form.id = ''

  // 重置表单数据
	nextTick(() => {
		dataFormRef.value?.resetFields();
	});

  // 获取sthcloudPpkSloveTask信息
  if (id) {
    form.id = id
    getSthcloudPpkSloveTaskData(id)
  }
};

// 提交
const onSubmit = async () => {
	const valid = await dataFormRef.value.validate().catch(() => {});
	if (!valid) return false;

	try {
    loading.value = true;
		form.id ? await putObj(form) : await addObj(form);
		useMessage().success(form.id ? '修改成功' : '添加成功');
		visible.value = false;
		emit('refresh');
	} catch (err: any) {
		useMessage().error(err.msg);
	} finally {
    loading.value = false;
  }
};


// 初始化表单数据
const getSthcloudPpkSloveTaskData = (id: string) => {
  // 获取数据
  loading.value = true
  getObj({id: id}).then((res: any) => {
    Object.assign(form, res.data[0])
  }).finally(() => {
    loading.value = false
  })
};

// 暴露变量
defineExpose({
  openDialog
});
</script>
